/////////////////////////////////////////////
// AcApDocManagerReactor reactors.

#include "StdAfx.h"
#include "StdArx.h"
#include "WindoTypeDlg.h"

extern CWindoTypeDlg* gpDlg;

CDocReact::CDocReact(const bool autoInitAndRelease)
{
	m_autoInitAndRelease = autoInitAndRelease;
	if (m_autoInitAndRelease)
		if (NULL != acDocManager)
			acDocManager->addReactor(this);
		else
			m_autoInitAndRelease = false;
}

CDocReact::~CDocReact()
{
	if (m_autoInitAndRelease)
		if (NULL != acDocManager)
			acDocManager->removeReactor(this);
}

void CDocReact::documentActivated(AcApDocument* pActivatedDoc)
{
	// TODO: implement this function.
	if(gpDlg)
	{

		CString fName;
		CString mainTitle("Window Parameters Modeless - ");
		AcApDocument *pCurrDoc = acDocManager->curDocument();
		fName = pCurrDoc->docTitle();
		mainTitle += fName;

		gpDlg->SetWindowText(mainTitle);
		gpDlg->SetFocus();

		CButton *pWindoType;
		CWnd *pEdBox;
		CString str_edboxVal;
		CString strWindType(windInfo.windType);

		if(strWindType == "Rect")
		{
			pWindoType = (CButton *) gpDlg->GetDlgItem(IDC_RB_TYPERECT);
			pWindoType->SetCheck(1);
			pWindoType = (CButton *) gpDlg->GetDlgItem(IDC_RB_TYPEARCH);
			pWindoType->SetCheck(0);
			pWindoType = (CButton *) gpDlg->GetDlgItem(IDC_RB_TYPEAPEX);
			pWindoType->SetCheck(0);
		}
		else if(strWindType == "Arch")
		{
			pWindoType = (CButton *) gpDlg->GetDlgItem(IDC_RB_TYPEARCH);
			pWindoType->SetCheck(1);
			pWindoType = (CButton *) gpDlg->GetDlgItem(IDC_RB_TYPERECT);
			pWindoType->SetCheck(0);
			pWindoType = (CButton *) gpDlg->GetDlgItem(IDC_RB_TYPEAPEX);
			pWindoType->SetCheck(0);
		}
		else	// It must be and "Apex" type of window
		{
			pWindoType = (CButton *) gpDlg->GetDlgItem(IDC_RB_TYPEAPEX);
			pWindoType->SetCheck(1);
			pWindoType = (CButton *) gpDlg->GetDlgItem(IDC_RB_TYPEARCH);
			pWindoType->SetCheck(0);
			pWindoType = (CButton *) gpDlg->GetDlgItem(IDC_RB_TYPERECT);
			pWindoType->SetCheck(0);
		}

		pEdBox = gpDlg->GetDlgItem(IDC_EDIT_COLS);
		pEdBox->SetWindowText(itoa(windInfo.m_nCols, str_edboxVal.GetBuffer(80), 10));

		pEdBox = gpDlg->GetDlgItem(IDC_EDIT_ROWS);
		pEdBox->SetWindowText(itoa(windInfo.m_nRows, str_edboxVal.GetBuffer(80), 10));

		acdbRToS(windInfo.m_dWindHt, 2, 3, str_edboxVal.GetBuffer(80));
		gpDlg->m_ctrlEdHeight.SetWindowText(str_edboxVal);

		acdbRToS(windInfo.m_dWindWt, 2, 3, str_edboxVal.GetBuffer(80));
		gpDlg->m_ctrlEdWidth.SetWindowText(str_edboxVal);

		acdbRToS(windInfo.m_dXVal, 2, 3, str_edboxVal.GetBuffer(80));
		gpDlg->m_ctrlEdXVal.SetWindowText(str_edboxVal);

		acdbRToS(windInfo.m_dYVal, 2, 3, str_edboxVal.GetBuffer(80));
		gpDlg->m_ctrlEdYVal.SetWindowText(str_edboxVal);
	}
}

